<?php
/**
 * Created by liuniukeji.com
 * User: 用户积分
 * Date: 16-3-31
 * @author:zhaojiping QQ: 17620286
 */

namespace Common\Model;
use Think\Model;

class YunshangUserCashAccountModel extends Model{
    protected $dbName = 'YuShangZhiJia';
    protected $tablePrefix = 'dbo.';
    protected $tableName = 'UserCashAccount';
     /**
     * 根据手机号查取账户余额
     * 
     */
    public function getCashAccount($username){
        $getCash=$this->where("userAccount='".$username."'")->find('TotalCash');
        return $getCash;
    }
    /**
     * 收到红包增加余额
     * @param username account
     * @return 
     */
    public function add_cash_account($username,$account,$i=0){
        $this->isAccount($username);
        $this->where("userAccount='".$username."'")->setInc('TotalCash',$account);
        return $getCash;
    }
    /**
     * 查询该账户是否存在 不存在增加一条新的数据
     * @param 
     * @return
     */
    public function isAccount($username){
        $getCash=$this->where("userAccount='".$username."'")->find();
        if(!$getCash){
            $array=array(
                'userAccount'=>$username,
                'TotalCash'=>0,
                'UsedCash'=>0,
                'ModifyTime'=>date('Y-m-d H:i:s'),
                'IsLocked'=>False,
                'HasLockedCash'=>0,
            );
           $this->data($array)->add();
        }
        return true;
    }
}
